﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using EC_Agent.AgentClass;

namespace EC_Agent.Models
{
    public class NhaCungCapModels
    {
        public DataSet ListNhaCungCap()
        {
            DataService ds = new DataService();
            return ds.ShowData("ListNhaCungCap");
        }

        public DataSet ListUrlNhaCungCap(string TenDV)
        {
            SqlParameter[] parameters = new SqlParameter[1];
            parameters[0] = new SqlParameter("@TenLoaiDV", TenDV);
            DataService ds = new DataService();
            ds.Connect();
            DataSet dataset = ds.ExcuteProcedureGetDataSet("ListUrlNhaCungCap", parameters);
            ds.Disconnect();
            return dataset;
        }

        public int InsertNhaCungCap(NhaCungCapInfo ncc)
        {
            SqlParameter[] parameters = new SqlParameter[12];
            parameters[0] = new SqlParameter("@TenNCC", ncc.TenNCC);
            parameters[1] = new SqlParameter("@LoaiDV", ncc.LoaiDV);
            parameters[2] = new SqlParameter("@DiaChi", ncc.DiaChi);
            parameters[3] = new SqlParameter("@Email", ncc.Email);
            parameters[4] = new SqlParameter("@DienThoai", ncc.DienThoai);
            parameters[5] = new SqlParameter("@UsernameA", ncc.UsernameA);
            parameters[6] = new SqlParameter("@PasswordA", ncc.PasswordA);
            parameters[7] = new SqlParameter("@WS", ncc.WS);
            parameters[8] = new SqlParameter("@TaiKhoan", ncc.TaiKhoan);
            parameters[9] = new SqlParameter("@TinhTrang", ncc.TinhTrang);
            parameters[10] = new SqlParameter("@HeSoNCC", ncc.HeSoNCC);
            parameters[11] = new SqlParameter("@HeSoGiaBan", ncc.HeSoGiaBan);
            DataService ds = new DataService();
            ds.Connect();
            ds.ExcuteProcedure("InsertNhaCungCap", parameters);
            ds.Disconnect();
            return 1;

        }

        public int UpdateNhaCungCap(NhaCungCapInfo ncc)
        {
            SqlParameter[] parameters = new SqlParameter[13];
            parameters[0] = new SqlParameter("@TenNCC", ncc.TenNCC);
            parameters[1] = new SqlParameter("@LoaiDV", ncc.LoaiDV);
            parameters[2] = new SqlParameter("@DiaChi", ncc.DiaChi);
            parameters[3] = new SqlParameter("@Email", ncc.Email);
            parameters[4] = new SqlParameter("@DienThoai", ncc.DienThoai);
            parameters[5] = new SqlParameter("@UsernameA", ncc.UsernameA);
            parameters[6] = new SqlParameter("@PasswordA", ncc.PasswordA);
            parameters[7] = new SqlParameter("@WS", ncc.WS);
            parameters[8] = new SqlParameter("@TaiKhoan", ncc.TaiKhoan);
            parameters[9] = new SqlParameter("@TinhTrang", ncc.TinhTrang);
            parameters[10] = new SqlParameter("@HeSoNCC", ncc.HeSoNCC);
            parameters[11] = new SqlParameter("@HeSoGiaBan", ncc.HeSoGiaBan);
            parameters[12] = new SqlParameter("@MaNhaCungCap", ncc.MaNhaCungCap);
            DataService ds = new DataService();
            ds.Connect();
            ds.ExcuteProcedure("UpdateNhaCungCap", parameters);
            ds.Disconnect();
            return 1;
        }

        public int UpdateTTNhaCungCap(NhaCungCapInfo ncc)
        {
            SqlParameter[] parameters = new SqlParameter[2];
            parameters[0] = new SqlParameter("@MaNhaCungCap", ncc.MaNhaCungCap);
            parameters[1] = new SqlParameter("@TinhTrang", ncc.TinhTrang);
            DataService ds = new DataService();
            ds.Connect();
            ds.ExcuteProcedure("UpdateTTNhaCungCap", parameters);
            ds.Disconnect();
            return 1;

        }

        public int DeleteNhaCungCap(NhaCungCapInfo ncc)
        {
            SqlParameter[] parameters = new SqlParameter[1];
            parameters[0] = new SqlParameter("@MaNhaCungCap", ncc.MaNhaCungCap);
            DataService ds = new DataService();
            ds.Connect();
            ds.ExcuteProcedure("DeleteNhaCungCap", parameters);
            ds.Disconnect();
            return 1;

        }
    }
}